package com.module.lemlin.util

import com.blankj.utilcode.util.ToastUtils
import com.module.lemlin.base.BaseApplication
import com.tencent.mm.opensdk.openapi.IWXAPI
import com.tencent.mm.opensdk.openapi.WXAPIFactory
import com.tencent.tauth.IUiListener
import com.tencent.tauth.Tencent
import com.tencent.tauth.UiError


const val THUMB_SIZE = 150
const val WX_APP_ID = "wx846bca23e6d2d499"
const val QQ_APP_ID = "1111508609"

val iwxapi: IWXAPI by lazy {
    WXAPIFactory.createWXAPI(
        BaseApplication.INSTANCE, WX_APP_ID
    )
}

val iqqapi: Tencent by lazy {
    Tencent.createInstance(QQ_APP_ID, BaseApplication.INSTANCE)
}

val isWXAppInstalled: Boolean by lazy {
    if (!iwxapi.isWXAppInstalled) {
        ToastUtils.showShort("请检查手机是否已安装微信")
    }
    iwxapi.isWXAppInstalled
}

val isQQAppInstalled: Boolean by lazy {
    if (!iqqapi.isQQInstalled(BaseApplication.INSTANCE)) {
        ToastUtils.showShort("请检查手机是否已安装QQ")
    }
    iqqapi.isQQInstalled(BaseApplication.INSTANCE)
}

 val iUiListener = object : IUiListener {
    override fun onComplete(p0: Any?) = Unit

    override fun onCancel() = Unit

    override fun onWarning(p0: Int) = Unit

    override fun onError(p0: UiError?) {
        ToastUtils.showShort(p0.toString())
    }
}